/*
 * TimeLabel.cpp
 *
 *  Created on: Feb 16, 2012
 *      Author: hzheng
 */

#include "TimeLabel.h"
#include  <unistd.h>
#include <ctime>
#include <sstream>
#include "errorcode.h"
namespace NS_LCD_AFW
{

CTimeLabel::CTimeLabel() :
		m_bRun(true)
{
	this->setAutoDelete(false);
}

CTimeLabel::~CTimeLabel()
{
	stop();

}

int CTimeLabel::stop()
{
	m_bRun = false;
	this->join();
}

void CTimeLabel::run()
{
	time_t curtime;
	static char buf[64] =
	{ 0 };
	while (m_bRun)
	{
		curtime = time(NULL);
		strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&curtime));
		this->setText(buf);
		this->invalidate();
		sleep(1);
	}
}

int CTimeLabel::onCreate()
{
	int iRet = ERR_SUCCESS;
	if (ERR_SUCCESS != (iRet = CLabel::onCreate()))
	{
		return iRet;
	}

	this->start();
	return ERR_SUCCESS;
}

}

/* namespace NS_LCD_AFW */
